<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head id="MyHead">
    <script src="../resources/Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="../resources/Scripts/jquery.easyui.min-1.3.5.js" type="text/javascript"></script>
    <script src="../resources/Scripts/jquery.datagrid.js" type="text/javascript"></script>
    <script src="../resources/Scripts/JScriptIndex.js" type="text/javascript"></script>
    <link href="../resources/Content/Default.css" rel="stylesheet" type="text/css" />
    <link href="../resources/Content/IndexStyle.css" rel="stylesheet" type="text/css" />
    <link href="../resources/css/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../resources/Scripts/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <link href="../resources/css/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <title>支队受理批次表</title>
    <script type="text/javascript" language="javascript">
         $(function () {
             $.extend($.fn.datagrid.methods, {
                 addToolbarItem: function (jq, items) {
                     return jq.each(function () {
                         var dpanel = $(this).datagrid('getPanel');
                         var toolbar = dpanel.children("div.datagrid-toolbar");
                         if (!toolbar.length) {
                             toolbar = $("<div class=\"datagrid-toolbar\"><table cellspacing=\"0\" cellpadding=\"0\"><tr></tr></table></div>").prependTo(dpanel);
                             $(this).datagrid('resize');
                         }
                         var tr = toolbar.find("tr");
                         for (var i = 0; i < items.length; i++) {
                             var btn = items[i];
                             if (btn == "-") {
                                 $("<td><div class=\"datagrid-btn-separator\"></div></td>").appendTo(tr);
                             } else {
                                 var td = $("<td></td>").appendTo(tr);
                                 var b = $("<a href=\"javascript:void(0)\"></a>").appendTo(td);
                                 b[0].onclick = eval(btn.handler || function () { });
                                 b.linkbutton($.extend({}, btn, {
                                     plain: true
                                 }));
                             }
                         }
                     });
                 },
                 removeToolbarItem: function (jq, param) {
                     return jq.each(function () {
                         var dpanel = $(this).datagrid('getPanel');
                         var toolbar = dpanel.children("div.datagrid-toolbar");
                         var cbtn = null;
                         if (typeof param == "number") {
                             cbtn = toolbar.find("td").eq(param).find('span.l-btn-text');
                         } else if (typeof param == "string") {
                             cbtn = toolbar.find("span.l-btn-text:contains('" + param + "')");
                         }
                         if (cbtn && cbtn.length > 0) {
                             cbtn.closest('td').remove();
                             cbtn = null;
                         }
                     });
                 }
             });
         });
    </script>
    
    <style type="text/css">
    .line{ clear:both;  overflow:hidden;zoom:1;}
    .editor-label{ width:80px; text-align:left; float:left; height:26px; margin-top:8px; padding-left:4px;}
    .editor-field{ width:260px; text-align:left; float:left; height:26px;margin-top:8px; margin-right:16px;}
    .blueline{ border-bottom:#95b8e7 1px solid; margin-bottom:10px; padding-bottom:10px;}
    .height80{ height:70px; padding-top:3px;}
    .TextArea{ width:260px; height:60px;border:#95b8e7 1px solid;}
    .editor-field input,.input-textbox{border:#95b8e7 1px solid; line-height:18px; width:100%;}
    .stupic{ position:absolute; top:40px; left:264px;}
    </style>

    <script src="/Res/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
                                         
    <script type="text/javascript" language="javascript">
        $(function () {

            $("#cannelParm").click(function () {
                $('#wAdd').dialog("close");
            });

            $("#addParm").click(function () {
                //$("#ff").submit();

                if ($("#detTitle").val() == "") {
                    $.messager.alert('系统提示：', '请输入批次标题！', 'warning');
                    return false;
                }
                if ($("#detManagePeople").val() == "") {
                    $.messager.alert('系统提示：', '请输入办理人！', 'warning');
                    return false;
                }
                //alert($('#sp_cate').combobox('getValue'));
                if ($('#detManageDate').val() == "") {
                    $.messager.alert('系统提示：', '请选择办理日期！', 'warning');
                    return false;
                }

                if ($("#action").val() == "add") {

                    $.ajax({
                        url: "/Create",
                        type: "Post",
                        data: $("#ff").serialize(),
                        dataType: "json",
                        success: function (data) {
                            //$.messager.alert('系统提示：', '新增信息成功！', 'info');
                            $("#detTitle").val("");
                            $("#detContent").val("");
                            $.messager.alert('系统提示：', data, 'info');
                            $('#wAdd').dialog("close");
                            $('#flexigridData').form('clear');
                            $('#flexigridData').datagrid('reload');
                        }
                    });
                }
                //alert($("#action").val());
                if ($("#action").val() == "update") {
                    $.ajax({
                        url: "../B_DetaAccept/Edit/" + $("#pk_id").val(),
                        type: "Post",
                        data: $("#ff").serialize(),
                        dataType: "json",
                        success: function (data) {
                            //$.messager.alert('系统提示：', '新增信息成功！', 'info');
                            $("#detTitle").val("");
                            $("#detContent").val("");
                            $.messager.alert('系统提示：', data, 'info');
                            $('#wAdd').dialog("close");
                            $('#flexigridData').form('clear');
                            $('#flexigridData').datagrid('reload');
                        }
                    });
                }
            });



            $('#flexigridData').datagrid({
                iconCls: 'icon-site',
                width: 'auto',
                height: 'auto',
                nowrap: false,
                striped: true,
                collapsible: true,
                singleSelect: true,
                url: '/showList', //获取数据的url
                
                sortName: 'pk_id',
                sortOrder: 'desc',
                idField: 'pk_id',

                toolbar: [
                    {
                         text: '创建受理批次',
                         iconCls: 'icon-add',
                         handler: function () {
                             return flexiCreate();
                         }
                     }, "-", {
                         text: '修改受理批次',
                         iconCls: 'icon-edit',
                         handler: function () {
                             return flexiModify();
                         }
                     }, "-", {
                         text: '批次状态',
                         iconCls: 'icon-remove',
                         handler: function () {
                             return updateState();
                         }
                     }, "-", {
                         text: '选择学员',
                         iconCls: 'icon-edit',
                         handler: function () {
                             return selectPici();
                         }
                     }],
                onDblClickRow: onDblClickRow,
                columns: [[


          	{ field: 'detId', title: '<label for="detId">批次编号</label>', width: 75 }
          , { field: 'detTitle', title: '<label for="detTitle">批次标题</label>', width: 175 }
          , { field: 'detContent', title: '<label for="detContent">批次内容</label>', width: 275 }
          , { field: 'detManagePeople', title: '<label for="detManagePeople">办理人</label>', width: 75 }
          , { field: 'detManageDate', title: '<label for="detManageDate">办理日期</label>', width: 75
                    /*  ,formatter: function (value, rec) {
                        if (value) {
                            return dateConvert(value);
                        } 
                    }*/
          }
          , { field: 'detStatus', title: '<label for="detStatus">批次状态</label>', width: 75 }
          , { field: 'detCreateName', title: '<label for="detCreateName">创建人</label>', width: 75 }
          , { field: 'detCreateDate', title: '<label for="detCreateDate">创建日期</label>', width: 75
                /*     , formatter: function (value, rec) {
                        if (value) {
                            return dateConvert(value);
                        } 
                    }*/
          }
          , { field: 'detModifyName', title: '<label for="detModifyName">修改人</label>', width: 75 }
          , { field: 'detModifyDate', title: '<label for="detModifyDate">修改时间</label>', width: 75
/*                     , formatter: function (value, rec) {
                        if (value) {
                            return dateConvert(value);
                        } 
                    } */
          }
                ]],
                pagination: true,
                rownumbers: true

            });

            var parent = window.dialogArguments; //获取父页面
            if (parent == "undefined" || parent == null) {
                //    不是在iframe中打开的
            } else {
                //隐藏所有的按钮和分隔符
                $(".l-btn.l-btn-plain").hide();
                $(".datagrid-btn-separator").hide();
                //添加选择按钮
                $('#flexigridData').datagrid("addToolbarItem", [{ "text": "选择", "iconCls": "icon-ok", handler: function () { flexiSelect(); } }]);
            }
        });

        //“查询”按钮，弹出查询框
        function flexiQuery() {

            //将查询条件按照分隔符拼接成字符串
            var search = "";
            $('#divQuery').find(":text,:selected,select,textarea,:hidden,:checked,:password").each(function () {
                search = search + this.id + "&" + this.value + "^";
            });
            //执行查询                        
            $('#flexigridData').datagrid('reload', { search: search });

        };

        function onDblClickRow(rowIndex, rowData) {
            //var selected = $("#flexigridData").datagrid('getSelections'); //获取所有行集合对象
            //alert(rowData["detTitle"]);
            //var obj = selected[rowIndex]; //index为当前右键行的索引，指向当前行对象
            parent.addTab(rowData["detTitle"], "../B_DetaAccept/SelStu/" + rowData["pk_id"], "tu1001", true, rowData["pk_id"]);
        }

        function selectPici() {
            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }
            parent.addTab(rows[0].detTitle, "../B_DetaAccept/SelStu/" + rows[0].pk_id, "tu1001", true, rows[0].pk_id);
        }

        //“导出”按钮     在6.0版本中修改
        function flexiExport() {

            //将查询条件按照分隔符拼接成字符串
            var search = "";
            $('#divQuery').find(":text,:selected,select,textarea,:hidden,:checked,:password").each(function () {
                search = search + this.id + "&" + this.value + "^";
            });

            var p = $('#flexigridData').datagrid('options').columns[0];
            var field = []; //所有的列名
            var title = []; //所有的标题名称
            $(p).each(function () {
                field.push(this.field);
                title.push(this.title);
            });

            $.post("../B_DetaAccept/Export",
                {
                    title: title.join(","),
                    field: field.join(","),
                    sortName: $('#flexigridData').datagrid('options').sortName,
                    sortOrder: $('#flexigridData').datagrid('options').sortOrder,
                    search: search
                }, function (res) {
                    window.location.href = res;

                });
        };
        //“选择”按钮，在其他（与此页面有关联）的页面中，此页面以弹出框的形式出现，选择页面中的数据
        function flexiSelect() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].pk_id);
            }
            arr.push("^");
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].detId);
            }
            //主键列和显示列之间用 ^ 分割   每一项用 , 分割
            if (arr.length > 0) {//一条数据和多于一条
                returnParent(arr.join("&")); //每一项用 & 分割
            }
        }

        //毕业处理
        function updateState() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }
            else {

                $('#divUpQuery').dialog({
                    buttons: [{
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: function () {
                            var arr = [];
                            for (var i = 0; i < rows.length; i++) {
                                arr.push(rows[i].pk_id);
                            }

                            var statusvalue = $("#detStatus1").val();
                            if (statusvalue == "") {
                                $.messager.alert('操作提示', '请选择批次状态!', 'info');
                                return false;
                            }
                            $.messager.confirm('操作提示', "确认修改批次状态吗？", function (r) {
                                if (r) {

                                    $.post("../../B_DetaAccept/updateState", { query: arr.join(","), statusvalue: statusvalue }, function (res) {

                                        if (res == "OK") {
                                            //移除删除的数据
                                            $('#divUpQuery').dialog("close");
                                            $.messager.alert('操作提示', '修改成功!', 'info');

                                            $("#flexigridData").datagrid("reload");
                                            $("#flexigridData").datagrid("clearSelections");

                                        }
                                        else {
                                            $.messager.alert('操作提示', res, 'info');
                                        }
                                    });
                                }
                            });

                        }

                    },
                     {
                         text: '取消',
                         iconCls: 'icon-cancel',
                         handler: function () {
                             $('#divUpQuery').dialog("close");
                         }
                     }]
                });
                $('#divUpQuery').dialog("open");
                //****************
            }
        }
        //导航到查看详细的按钮
        function getView() {

            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                window.location.href = "../B_DetaAccept/Details/" + arr[0].pk_id;

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;
        }
        //导航到创建的按钮
        function flexiCreate() {
            $("#action").val("add");
            $('#wAdd').dialog("open");
        }
        //导航到修改的按钮
        function flexiModify() {

            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                $("#action").val("update");
                $("#pk_id").val(arr[0].pk_id);
                $("#detId").val(arr[0].detId);

                var detStatus = removeHTMLTag(arr[0].detStatus);
                var statevalue = "";
                if (detStatus == "启用") {
                    statevalue = "0";
                } else if (detStatus == "禁用") {
                    statevalue = "1";
                } else if (detStatus == "归档") {
                    statevalue = "2";
                }
                $("#detStatus").val(statevalue);

                $("#detCreateName").val(arr[0].detCreateName);
                $("#detCreateDate").val(arr[0].detCreateDate);

                $("#detTitle").val(arr[0].detTitle);
                $("#detManagePeople").val(arr[0].detManagePeople);
                $("#detManageDate").val(dateConvert(arr[0].detManageDate));
                $("#detContent").val(arr[0].detContent);
                $('#wAdd').dialog("open");

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;

        };

        //js过滤HTML标签以及空格
        function removeHTMLTag(str) {
            str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
            str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
            //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
            str = str.replace(/ /ig, ''); //去掉 
            return str;
        }
        //删除的按钮
        function flexiDelete() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].pk_id);
            }

            $.messager.confirm('操作提示', "确认删除这 " + arr.length + " 项吗？", function (r) {
                if (r) {
                    $.post("../B_DetaAccept/Delete", { query: arr.join(",") }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据

                            $.messager.alert('操作提示', '删除成功!', 'info');
                            $("#flexigridData").datagrid("reload");
                            $("#flexigridData").datagrid("clearSelections");
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });

        };

    </script>

      <base target = "_self">
</head>
<body class="easyui-layout" style="padding:3px;">
    <table id="flexigridData" fit="true">
    </table>
    
    <div id="divQuery">
         
            <div class="input_search">
            
                    <label for="detId">批次编号</label>：
             
                    <input type='text' id='detId1'/>
               
            </div> 
            <div class="input_search">
            
                    <label for="detTitle">批次标题</label>：
             
                    <input type='text' id='detTitle1'/>
               
            </div>  
            <div class="input_search">
            
                    <label for="detManagePeople">办理人</label>：
             
                    <input type='text' id='detManagePeople1'/>
               
            </div> 
            <div class='input_search'>
              
                    <label for="detManageDate">办理日期</label>：
              
                    <input type="text" id="detManageDateStart_Time" onclick="WdatePicker({maxDate:'#F{$dp.$D(\'detManageDateEnd_Time\');}'})"  />
                    <span>到</span>
                    <input type="text" id="detManageDateEnd_Time" onclick="WdatePicker({minDate:'#F{$dp.$D(\'detManageDateStart_Time\');}'})" />
               
            </div> 
        <div class='input_search'>   <a href="#" onclick="flexiQuery()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">
            查 询</a>  </div>
    </div>
     <div id="wAdd" class="easyui-window" title="&nbsp;支队受理批次" closed="true"  collapsible="false" minimizable="false" maximizable="false" modal="true" data-options="iconCls:'icon-save'" style="width:400px;height:280px;padding:5px;">
           <div data-options="region:'North'" style="height:80px">
                <form id="ff" method="post">
                <input type="hidden" id="action" name="action" value="" />
                <input id="pk_id" name="pk_id" type="hidden" value="" />
                <input id="detId" name="detId" type="hidden" value="" />
                <input id="detCreateName" name="detCreateName" type="hidden" value="" />
                <input id="detCreateName" name="detCreateName" type="hidden" value="" />
                <input id="detStatus" name="detStatus" type="hidden" value="" />
            <div class="editor-label">
					<label for="detTitle">批次标题</label>：
            </div>
            <div class="editor-field">
                <input Value="2018年1月17号支队受理批次" id="detTitle" name="detTitle" type="text" value="" />
                
            </div>  
            <br style="clear: both;" />   
            <div class="editor-label">
                <label for="detManagePeople">办理人</label>：
            </div>
            <div class="editor-field">
                <input Value="王新超" id="detManagePeople" name="detManagePeople" type="text" value="" />
                
            </div>
            <br style="clear: both;" />   
            <div class="editor-label">
                <label for="detManageDate">办理日期</label>：
            </div>
            <div class="editor-field">
            <input id="detManageDate" name="detManageDate" onclick="WdatePicker()" style="width: 260px;" type="text" value="2018-01-17" />
            </div>
            <br style="clear: both;" />
            <div class="editor-label height80">
                <label for="detContent">批次内容</label>：
            </div>
            <div class="editor-field height80">
                <textarea class="TextArea" cols="20" id="detContent" name="detContent" rows="2">
</textarea>
                
            </div>
            <br style="clear: both;" />
            <div style="text-align:center; margin-top:10px;">
               <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" id="addParm">提 交</a>
               <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" id="cannelParm">取 消</a>
            </div>
            </form>
    </div>
    
    <div id="divUpQuery" title="批次状态" class="easyui-dialog" closed="true" modal="false"
        iconcls="icon-search" style="width:250px; height:130px; text-align:center;">
        <br />
      		批次状态:
      <select id="detStatus1" name="detStatus1" style="width:100px">
		<option value="" >请选择</option>
		<option value="0" >启用</option>
		<option value="1">禁用</option>
		<option value="2">归档</option>
	  </select>
    </div>  

</body>
</html>
